perm filename MAPS.BIG[E81,JMC]2 blob sn#617718 filedate 1981-10-10 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00005 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002
C00025 00003		We can regard coloring the dropped countries as a process of
C00029 00004	Notes:
C00039 00005	Results of coloring the map of the U.S.
C00043 ENDMK
C⊗;

                   COLORING MAPS AND THE KOWALSKI DOCTRINE
    
Kowalski (l974) enunciated the doctrine expressed by the formula

         program = logic + control

	The formula isn't precise, and it won't be precise until
someone proposes a precise and generally accepted notion of how
control is to be added to an expression of the logic of a program.
Nevertheless, the idea is attractive, and I believe it can be made to work
for some interesting class of programs.  It is analogous to my comparison
of epistemology and heuristics or Chomsky's competence and performance.

	Pereira and Porto (1981) give a logic program for coloring planar
maps with four colors and discuss how "intelligent
backtracking" can reduce the search involved in coloring a map from that
done by a straightforward PROLOG execution of the same
program.

	The discussion by Pereira and Porto treats coloring maps purely as
an example of logic programming, and the improvements they discuss apply
to all logic program systems.  We shall consider two mathematical ideas
about map coloring that go back to Kempe (1879), the paper containing the
original false proof of the four color theorem.  While Kempe's proof
was false, the ideas are good and were used in almost all subsequent work
including the recent successful proof.

	The question is whether an algorithm
involving these ideas can be regarded as a form of control adjoined to
the basic logic program or whether they necessarily involve a new program.
If they are to be regarded as control structures, it is not yet clear how
they are best expressed.  Of course, it is not hard to write a completely
new program in PROLOG or any other language expressing the algorithms, but
perhaps they can also be regarded as control attached to the Pereira-Porto logic.


2.  The Pereira-Porto logic program

	There are two parts.  The first expresses that the adjacent
countries must have different colors by listing the pairs of colors that
may be adjacent.  We have

(1)	next(yellow,blue).
	next(yellow,red).
	next(yellow,green).
	next(blue,yellow).
	etc. for all pairs of distinct colors.

	The remaining PROLOG statement is distinct for each map.  For the
map of Figure 1, which they use as an example,




(3 inches here for figure 1)





	Figure 1


it is

(2)	goal(R1,R2,R3,R4,R5,R6) ← next(R1,R2),next(R1,R3),next(R1,R5),
next(R1,R6),next(R2,R3),next(R2,R4),next(R2,R5),next(R2,R6),next(R3,R4),
next(R3,R6),next(R5,R6).

where each literal expresses the fact that a particular pair of adjacent
regions must be compatibly colored.

	Pereira and Porto give a trace of the execution of the program by
standard depth first PROLOG.  They point out that when an attempt to
satisfy a literal fails, because the two adjacent regions mentioned have
been assigned the same color, standard PROLOG will take back
the most recent assignment of a color even if the region most recently
colored was neither of those involved in the incompatibility.  Their
intelligent backtracking will change the color of one of the regions
giving the incompatibility.

	An outsider to logic programming may react unsympathetically and
comment that this is just one more example of a logic programming system,
with its standard way of doing searches, tripping over its own feet.
However, we should also recall that brief and easy statement of the PROLOG
program for the coloring and not give up this virtue without a fight.

	Nevertheless,
"intelligent backtracking" doesn't make (1) and (2) into a good coloring
program.  Indeed we shall argue that it doesn't even do full justice to the
logic of the program.  To see this we need two ideas of Kempe.


3.  Reducing the map

	Kempe (or perhaps someone still earlier)
noticed that countries with three or fewer neighbors present
no problem.  No matter how the rest of the map is colored, there is always
a color available for such a country.  This suggests "reducing the map" by
removing such countries and doing our trial-and-error coloring on the
reduced map, confident that once the reduced map is colored, the coloring
can be extended to the omitted countries.

	The idea is even more powerful, because eliminating countries with
three or fewer neighbors may remove enough neighbors from some other
countries so that they have three or fewer neighbors and can themselves be
removed.  Therefore, the reduction process should be continued until a
completely reduced map is obtained in which all countries have at least four
neighbors.
  The maps of the states of the U.S. and
the countries of Europe, Asia, Africa and South America all reduce
to null maps when countries with three or fewer neighbors are successively
eliminated

	Likewise the map of Figure 1 reduces to the empty map.  
Thus we may remove country 4 with two neighbors and country 5 with three
neigbors.  This leaves all the remaining countries with three or fewer
neighbors, so the second cycle of reduction leaves the null map.
reduced map.  Therefore, when we colored in the reverse order
1,2,3,6,4,5, each country is colored without changing the
color of any previously colored country.

	If the programmer performs this reduction before he writes the
goal statement, he will write

	goal(R1,R2,R3,R4,R5,R6) ← next(R1,R2),next(R1,R3),next(R1,R6),
next(R2,R3),next(R2,R6),next(R3,R6),next(R2,R4),next(R3,R4),next(R1,R5),
next(R2,R5),next(R5,R6).

	This PROLOG program will run with only the most local
backtracking.  Namely, after R1 has been chosen arbitrarily, several
values will have to be tried for each of the variables R1,R2,R3,R6,R4,and R5, but
once a value has been found that is compatible with the previously
determined variables, it won't have to be changed again.

	The new PROLOG program is logically equivalent to the previous
program because it is just a rearrangement of the literals of a
conjunction.  However, the programmer has done the control.  The
interesting question is whether the reduction can be expressed in some way
that can be regarded as adding control to the original logic, i.e.,
without changing the original logic.


4.  Kempe transformations

	Another idea of Kempe's can be used to strengthen the reduction
process, but regarding it as mere control added to the original logic program
seems even harder.

	The strengthened reduction procedure also removes countries with
four neighbors so that the reduced map contains only countries with five
or more neighbors.  The validity of this reduction depends on the following
Kempe proof
that if we have colored a partial map and want to add a country
with four neighbors, we can always revise the coloring of the partial map
to permit coloring the four neighbor country.

	If fewer than four colors have been used to color the neighbors,
there is no problem, so suppose that the four neighbors have been colored
with four different colors as shown in Figure 2.




(3 inches here for figure 2)





	Figure 2



	Consider the set  S  of all countries that can be reached from the
blue country A on top of Figure 2 by a path going through only blue and
yellow countries.  S  is called the blue-yellow Kempe component of
country A.  There are two cases.  Either it contains country C or not.  If
not, we recolor the partial map by reversing blue and yellow on all
countries in  S.  This still leaves the
partial map properly colored.
  Since
S  does not contain  C, C  remains yellow
while  A  has become yellow.  This makes blue available to extend the
coloring to X.

	In the other case, S  contains
C, i.e, there is a chain of adjacent countries from A to C each of which
is colored blue or yellow.  Then there cannot be a red-green chain from B
to D (by the topology of the plane or sphere), so that a red-green Kempe
transformation applied to the red-green Kempe component of B will make B
green, leaving red available to color X.

	The fact that a blue-yellow path from A to C blocks a red-green
path from B to D is where we have used the fact that the map is on a plane
or sphere.

	This justifies eliminating countries with four neighbors in the
reduction process.  If we have colored a partial map and want to add a
country with four neighbors, we can do so, but we may have to modify the
previous coloring by means of a Kempe transformation.

	Our improved coloring algorithm then reduces the map by repeatedly
dropping countries with four or fewer neighbors, colors the reduced map
exhaustively, and then colors the dropped countries in the reverse order
using Kempe transformations when necessary.


5. Realizing the reduction algorithm by control of the Pereira-Porto logic

	
	From the point of view of logic programming, successively
reducing the map by postponing countries with three or fewer neighbors
is an example of a more general notion - that of a @p[postponable
variable].  A variable in the body of a clause is postponable if
no matter how the other variables are assigned, there is a value for
this variable that causes all the goals involving that variable
to be satisfied.  Clearly any postponable variable can be postponed
to the end.  Moreover, just as in the map coloring problem, postponing
some variables may remove enough goals involving other variables so
that they in turn become postponable.

	If there were only one stage of postponement, we could regard
postponement as a case of selecting the first goal to be attempted,
the postponable variables being rejected for selection.  However, this
wouldn't prevent the selection of a variable postponable in the second
stage.  Therefore, the postponement process should be completed before
any goals are selected for attempt.

	The postponability of a variable is expressed by a postponement
lemma.  For example, the postponability of @i[R4] is expressed by
the formula

	@i[∀R2 R3.∃R4.(next(R2,R4) ∧ next(R3,R4))].

Notice that our quick recognition of the postoponability of @i[R4] is
based on the symmetry.  We say that whatever colors are assigned to
@i[R2] and @i[R3], a compatible color can be found for @i[R4].  We
don't have to enumerate the possible assignements to @i[R2] and @i[R3].
A program would have to do more work unless it also discovered or was told that
coloring problems are invariant when the names of the colors are
permuted.

	We can imagine several combinations of programmer and computer
effort in postponing variables.  We already discussed the case in
which the programmer himself re-ordered the goals in the clause.  The
other extreme is that the PROLOG compiler attempt to prove postponability
lemmas.  Since some cases of postponability may depend on some variables
already having values, additional postponements can be accomplished by
a suitable interpreter.  Since most variables in most programs are
not postponable, it seems wasteful to have the interpreter always
try for postponement.  Therefore, it is also possible for the user
to specify that the compiler and/or run-time system look for
postponable variables, perhaps by enclosing the clause or part of
it within which postponable variables may be expected within a
macro.  Thus the above program might be written

	@i[goal(R1,R2,R3,R4,R5,R6) ← postpone(next(R1,R2),next(R1,R3),...,etc.)].

	The most powerful way of achieving postponement is for the
programmer to use the full power of PROLOG to transform the body.
Alain Colmerauer wrote such a program for rewriting the
Pereira-Porto coloring program.  If the programmer can arbitrarily rewrite the
program he may
change the logic as well as the control.  However, we can imagine
that a restricted set of re-arrangement operators are used that is
guaranteed to only affect the control.

	I was informed by Herve Gallaire that the system for specifying
control described in (Gallaire 1981) could not express the postponement
heuristic for the coloring problem, but that a small modification to the
system would make it possible.


6. Realizing the Kempe transformation algorithm

	Realizing the Kempe transformation algorithm as control of the
Pereira-Porto logic presents a more difficult challenge
to the designers of control languages for logic programming.  Of course,
the postponement part of the algorithm is the same as before; the
difficulty comes when it is necessary to color a country with four
differently colored neighbors.

	The first step is to
identify opposite neighbors of the four neighbor country.  This depends
not merely on the fact that the map is planar but on the actual imbedding
in the plane.  This information has been discarded when the map is
represented as a graph.  If the graph is described by giving for each
country a list of its neigbors, the imbedding information can be including
by listing the neighbors in cyclic order - clockwise or counterclockwise.
Otherwise, it can be restored in general only with difficulty.  Figure 3
shows cases where this isn't trivial.  Of course, we can modify the
algorithm to try every pair of vertices to see if they are unconnected
by a path of their two colors.  The above argument shows that this is
guaranteed to succeeed but presumably at somewhat greater cost than if
the cyclic order is known.




	(3 inches for figure 3)

			Figure 3

	Looking for a changable country is a process of search whereby
only certain values are allowed for certain variables and goals that
become unsatisfied are re-satisfied by changing only certain variables
in certain ways.  A good control system for logic programs should
permit the expression of such strategies.


7. References

Pereira and Porto, Intelligent backtracking

Kempe 1879 paper

Kowalski's book

Colmerauer, Alain (1981) personal communication
	We can regard coloring the dropped countries as a process of
satisfying the goal of (2), using a very specific process of revising the
values of variables.  Whenever a Kempe transformation is made, all the
variables corresponding to countries in a Kempe component have their
values changed simultaneously in a specific way.  A very powerful means of
specifying control will be required.

	The Pereira-Porto selective backtracking is still required for
coloring reduced maps.  It will also do the right thing when the map is
divided into continents with no connections between countries in different
continents.  Even if the adjacencies are listed in a mixed order among
continents, it won't try to cure a problem in coloring one continent by
changing the color of another.  Also the reduction algorithms will work
ok in the multi-continent case.  However, we can still imagine some use
for a control algorithm that would first divide the map into connected
subsets.

	Another interesting case occurs when the map is divided into
two parts A and B by a ring C of three countries.  If we color A∪C and
B∪C separately, we can combine the colorings to get a coloring of the
whole map, but we may have to permute the colors on one component in
order to color C consistently.  Some of the research on the four color
theorem involved classifying colorings of larger rings.

	The coloring algorithms implicit in
( ) will involve a much more complex control process.  Other algorithms
for satisfying systems of constraints can also be studied as control added
to logic.

	To summarize, coloring maps may involve at least 5 kinds of control
applied to the original logic.

	1. Pereira-Porto selective backtracking.

	2. Kowalski-Bowen selection of a next goal.

	3. Postponement of postponable variables.  This may be done in
by virtue of a general theorem, i.e. that countries with three or fewer
neigbors are postponable or by an ad hoc theorem for a particular variable.

	4. Algorithms like Kempe transformations that revise previously
determined variables in problem dependent ways.

	5. Division of the problem into subproblems which can be solved
either independently or successively.
Notes:

1. The Pereira-Porto program has too limited an ontology to admit much
control to its ontology.  Maps, partial colorings of maps, and even
countries are not objects.  Heuristics may require additional objects
such as reduced maps and ordered lists of countries.

2. Program fragments

ok(y,b).
ok(b,y).
...

adj(r1,r2).
adj(r1,r3).
...

color(Map,X) :- reduce(Map,Y),color1(Y,Z),finish(Z,X).

colored(r1,R1) or colored(r1,R1,Partialmap)

goal(R1,...,R6) :- (putoff(r1);putoff(r2);ok(R1,R2));

Jul 13

3. In setting up the logic of the program, there is no need to be restricted
to clausal form.  Let's do an unprejudiced set theory axiomatization and
then see about expressing an algorithm in Horn clause form.
With the set theory we can construct heuristic entities like
coloring sequences as well as purely epistemological entities.
Perhaps Lisp or Prolog programs can also be entities.
Most likely literals, clauses, and sets of clauses with the same
head predicate symbols will have to be entities.

See color.ax[e81,jmc]

See maps.pr[e81,jmc]

4. There is a general method of achieving prolog goals which says that
some subgoals can be delayed because they can be achieved however the
others are achieved, while their achievement may interfere with the
achievement of the others.  Is this "method of postponable goals" usable
for other problems than coloring?

5. We must consider postponable goals and p. variables.  It seems that
one might often be able to prove a theorem to the effect that a certain
set of goals can be achieved with the freedom to determine the values
of variables x,...,z no matter what values are assigned to the other
variables.  If these are all the goals in which x,...,z appear, then
the goals and variables can be postponed.

6. It seems we can generalize Kempe transformations.  A set of variables
and the goals containing them may admit a group of transformations
that preserve the truth values of the goals.  The problem of assigning
professors and rooms to courses will admit such groups of transformations.
It is important to note that as with map coloring, the group of transformations
will in general depend on the decisions already made.

7. Postponing coloring countries with three or fewer neighbors is
legitimized by proving

	∀x y z ∃w.(n(x,w) ∧ n(y,w) ∧ n(z,w))

which is generally true where n(x,y) stands for what Pereira and Porto
call next(x,y).  Here we have a single relation which permits
postponing all countries with three or fewer neighbors.  In a less
homogeneous problem, we would expect that a postponable variable
in a body would have a special relation that could be proved in
order to postpone it.  Looking for postponable variables is obviously
expensive, so it must be under the user's control or the control of
some higher level program that knows that not seeking postponable
variables will lead to much backtracking.

	If we imagine (1) to be proved by first order logic using the ontology
of colors or even regions,
the proof may involve checking all 4↑3 = 64 combinations of x, y and z
and finding the required w.  The counting argument that if there are only
three of x, y, and z, then there is a fourth color for w requires a higher
level ontology.  Namely we must be able to argue about the cardinality of
sets of colors.
  However, this is a somewhat special case because of the
mutual similarity of the goals in a coloring problem.  In other cases,
the given ontology may permit reasonable proofs of the postponability
theorems, or at least there may be no advantage in going to a higher
level.

8. We suggest adding to Prolog a construction of the form

	reorderable(p1,...,pn)

Its meaning is logically the same as that of the list of literals (p1,...,pn),
but Prolog is allowed to reorder it by doing postponements and
immediacies.  Maybe we also need more specific re-orderings such as

	reorder(A,p1,...,pn)

where A is a rule for re-ordering.  We could allow meta rules or macros,
where

	macro(A([p1,...,pn],Macro-expansion))

applies the macro A to the clauses to get a macro-expansion which is
actually run.  Those macros that are merely re-orderings, i.e. change
the control but not the logic, seem to merit preferential treatment.

Aug 17

	In common sense reasoning, postponable variables are very
common, but their treatment is much more subtle than is required
by coloring problems.

Example: In planning a trip one ordinarily postpones deciding how to get to the
airport until after deciding what flight to take.  This is justified
by the fact that the decision about what flight to take is made on
criteria that do not include going to the airport.  On the other hand,
deciding on the flight determines how to go.  Notice that the postponability
of deciding how to go to the airport is an ad hoc decision and not
based on a general criterion like the variable appearing in only three
literals.

	Actually, the ways of getting to the airport can affect the
chosen flight.  One may decide to take the same flight as another
person in order to share transportation.  However, this is usually
a secondary consideration in the sense that it is used in a second
iteration of a plan.

(doctrine: Horn clauses and depth first search are in general the right
way to solve problems at the basic level.  Non-Horn clauses and other
kinds of search are done after some reification - at least reification
of tactics.  Hmm!  This seems to be in some contradiction to the
Kowalski doctrine).

Sept 13

	The output of postponement might well have the form proposed
by Monteiro (1981) for concurrent prolog.  Namely, the sets of goals
associated with each postponed variable are internally sequential
(connected by .) but
can be connected by + since they can be executed in parallel.  The groups
must be executed sequentially.  Thus the Pereira-Porto program is
rewritten


(next(R2,R4).next(R3,R4))+(next(R1,R5).next(R3,R5).next(R5,R6)))

1. attach postponable to Kowalski metaprolog
Results of coloring the map of the U.S.

| ?- cs(X).

X = [[ca|y],[az|b],[nev|g],[oreg|r],[wash|y],[ida|b],[ut|y],[mont|y],[wyo|r],[nm
|r],[colo|b],[tex|b],[ndak|r],[minn|y],[sdak|b],[la|y],[miss|g],[ark|r],[okla|y]
,[kans|r],[neb|y],[io|r],[mo|b],[ala|b],[fla|y],[scar|y],[ga|r],[ncar|b],[tenn|y
],[dc|b],[va|g],[wisc|b],[ill|y],[mich|r],[ind|b],[kent|r],[ohio|y],[wva|b],[md|
y],[del|b],[penn|r],[nj|y],[conn|g],[ny|b],[ri|y],[mass|r],[nh|b],[me|y],[vt|y]]

  23:22:10 PROLOG IO wait at 700271  Used 0:02:10.8 in 0:41:22, Load   0.74

248. pages, Entry vector loc 0 len 254000

0-233	 Private   R, W, E
367-400	 Private   R, W, E
401-466	 MRC:<PROLOG>PROLOG.EXE.1  7-74   R, CW, E
700-731	 <SUBSYS>PA1050.EXE.5  1-32   R, CW, E
732-733	 Private   R, W, E